Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@thi.ng/arrays

Package Overview
Dependencies
Maintainers
0
Versions
194
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@thi.ng/arrays

Array / Arraylike utilities

  • 2.10.8
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
114K
decreased by-22.51%
Maintainers
0
Weekly downloads
 
Created
Source

@thi.ng/arrays

npm version npm downloads Mastodon Follow

[!NOTE] This is one of 200 standalone projects, maintained as part of the @thi.ng/umbrella monorepo and anti-framework.

🚀 Please help me to work full-time on these projects by sponsoring me on GitHub. Thank you! ❤️

About

Array / Arraylike utilities.

Status

STABLE - used in production

Search or submit any issues for this package

Installation

yarn add @thi.ng/arrays

ESM import:

import * as arr from "@thi.ng/arrays";

Browser ESM import:

<script type="module" src="https://esm.run/@thi.ng/arrays"></script>

JSDelivr documentation

For Node.js REPL:

const arr = await import("@thi.ng/arrays");

Package sizes (brotli'd, pre-treeshake): ESM: 3.00 KB

Dependencies

Note: @thi.ng/api is in most cases a type-only import (not used at runtime)

Usage examples

Six projects in this repo's /examples directory are using this package:

ScreenshotDescriptionLive demoSource
k-means clustering visualizationDemoSource
Randomized 4-point 2D color gradient image generatorDemoSource
Animated, iterative polygon subdivisions & visualizationDemoSource
Responsive image gallery with tag-based Jaccard similarity rankingDemoSource
Responsive & reactively computed stacked column layoutDemoSource
Tree-based UI to find & explore thi.ng projects via their associated keywordsDemoSource

API

Generated API docs

Binary search result predicates

The following predicates can be used to perform predecessor / successor queries using binarySearch().

  • bsLT() - Returns index of last item less than search value or -1 if no such values exist
  • bsLE() - Similar to bsLT(), but for less-than-equals queries
  • bsGT() - Returns index of first item greater than search value or -1 if no such values exist
  • bsGE() - Similar to bsGT(), but for less-than-equals queries
  • bsEQ() - Merely syntax sugar, casting any non-found result indices to -1
import { binarySearch, bsGT, bsLT } from "@thi.ng/arrays";

const src = [10, 20, 30, 40];

bsLT(binarySearch(src, 25))
// 1

// greater-than queries also require the array length

bsGT(binarySearch(src, 25), src.length)
// 2

bsGT(binarySearch(src, 40), src.length)
// -1

Authors

If this project contributes to an academic publication, please cite it as:

@misc{thing-arrays,
  title = "@thi.ng/arrays",
  author = "Karsten Schmidt",
  note = "https://thi.ng/arrays",
  year = 2018
}

License

© 2018 - 2024 Karsten Schmidt // Apache License 2.0

Keywords

FAQs

Package last updated on 27 Dec 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc